{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">新增项目</h3>
    <table class="layui-table layui-table-form">
        {if condition="$eid gt 0"}
        <input type="hidden" name="eid" value="{$eid}" lay-verify="required">
        {else/}
        <tr>
            <td class="layui-td-gray">所在企业<font>*</font></td>
            <td colspan="5">
                <select name="eid" lay-verify="required" lay-reqText="请选择所属企业" lay-filter="asyncEidSelect">
                    <option value="0">系统管理员</option>
                    {volist name="enterprise" id="v"}
                    <option value="{$v.id}" {notempty name="$detail.eid"}{eq name="$v.id" value="$detail.eid"} selected{/eq}{/notempty} >{$v.title}</option>
                    {/volist}
                </select>
            </td>
        </tr>
        {/if}
      <tr>
          <td class="layui-td-gray">项目名称<font>*</font></td>
          <td><input type="text" name="name" lay-verify="required" {notempty name="$detail.name"}value="{$detail.name}" {/notempty} lay-reqText="请输入项目名称" autocomplete="off" placeholder="请输入项目名称" class="layui-input"></td>
        </td>
          <td class="layui-td-gray">负责人<font>*</font>
          <td>
              <select name="director_uid" lay-verify="required" lay-reqText="请选择负责人" lay-filter="asyncUserSelect"
                      id="async-User-select">
                  {volist name="user" id="v"}
                  <option value="{$v.id}" {notempty name="$detail.director_uid"}{eq name="$v.id" value="$detail.director_uid"}
                          selected{/eq}{/notempty} >{$v.name}</option>
                  {/volist}
              </select>
          </td>
      </tr>
        <tr>

            <td class="layui-td-gray">开始时间<font>*</font></td>
            <td>
                <input id="start_time" name="start_time" autocomplete="off" {notempty name="$detail.fmt_start_time"}value="{$detail.fmt_start_time}" {/notempty} class="layui-input" value="" readonly lay-verify="required" placeholder="请选择开始时间" lay-reqText="请选择开始时间">
            </td>
            <td class="layui-td-gray">结束时间<font>*</font></td>
            <td>
                <input id="end_time" name="end_time" autocomplete="off" class="layui-input" {notempty name="$detail.fmt_end_time"}value="{$detail.fmt_end_time}" {/notempty} readonly lay-verify="required" placeholder="请选择结束时间" lay-reqText="请选择结束时间">
            </td>
        </tr>
        </tr>
        <tr>
            <td class="layui-td-gray">项目编号<font>*</font></td>
            <td>
                <input type="text" name="code" lay-verify="required"
                       {notempty name="$detail.code"}value="{$detail.code}" {/notempty} lay-reqText="请输入项目编号" autocomplete="off" placeholder="请输入项目编号" class="layui-input">
            </td>
            <td class="layui-td-gray">项目类型<font>*</font></td>
            <td colspan="3">
                <input type="text" name="type" lay-verify="required" {notempty name="$detail.type"}value="{$detail.type}" {/notempty} lay-reqText="请输入项目类型" autocomplete="off" placeholder="请输入项目类型" class="layui-input"></td>
            </td>
        </tr>
        <input type="hidden" name="id" ,  {notempty name="$detail.id"}value="{$detail.id}" {/notempty} >
    </table>
    <div class="py-3">
	   <input type="hidden" name="scene" value="add">
      <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','employeepicker'];
	function gouguInit() {
		var form = layui.form,tool=layui.tool,employeepicker = layui.employeepicker ,  table = layui.table;
        function getPageUser(eid) {
            $.getJSON('/home/goodsCollar/getPageUser?eid=' + eid, function (res) {
                var html = '';
                layui.each(res.data, function (index, item) {
                    html += '<option value="' + item.id + '">' + item.name + '</option>';
                });
                document.getElementById('async-User-select').innerHTML = html;
                form.render($('#async-User-select')); // 重新渲染select
                // 模拟数据输出

                console.log(res); // 被选中的值
            });
        }
        var eid = '{$eid}'
        form.on('select(asyncEidSelect)', function (data) {
            eid = data.value;
            table.reload('ID-table-demo-templet', {
                where: {
                    eid
                }
            });
        });
        form.on('select(asyncEidSelect)', function (data) {
            getPageUser(data.value);
        });
		//监听提交
		form.on('submit(webform)', function (data) {
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					tool.sideClose(1000);
				}
			}
			tool.post("/home/item/add", data.field, callback);
			return false;
		});

        var form = layui.form,
            tool=layui.tool,
            oaTool=layui.oaTool,
            laydate = layui.laydate;
        //日期时间范围
        laydate.render({
            elem: '#start_time',
            type: 'date',
            format: 'yyyy-MM-dd',
            showBottom: false
        });
        //日期时间范围
        laydate.render({
            elem: '#end_time',
            type: 'date',
            format: 'yyyy-MM-dd',
            showBottom: false
        });

    }
</script>
{/block}
<!-- /脚本 -->